package netty.test11HttpServer;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * http 服务器,(浏览器输入地址后，会请求2次，打开firebug 会发现，还请求了一个图标文件 favicon.ico，
 * 这个是每个网站都有的)，
 * 这里假如我们不想接受这个图标文件的请求的，话，我们可以给过滤掉，（在 TestHttpServerHandler#channelRead0 中处理 ）
 */
public class TestServer {
    public static void main(String[] args) throws Exception{
        EventLoopGroup bossGroup=new NioEventLoopGroup();
        NioEventLoopGroup workerGroup=new NioEventLoopGroup();
        try{
            ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(bossGroup,workerGroup).channel(NioServerSocketChannel.class)
            .childHandler(new TestInitializer());
            ChannelFuture channelFuture = serverBootstrap.bind(6668).sync();
            System.out.println("server is reading");
            //对关闭通道进行监听
            channelFuture.channel().closeFuture().sync();
        }finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }
}
